package logic

import (
	"context"
	"course_srv/course"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerCourseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerCourseAddLogic {
	return &HandlerCourseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerCourseAddLogic) HandlerCourseAdd(req *types.RequestCourseAdd) (resp *types.Response, err error) {

	courseAdd, err := l.svcCtx.CourseSrv.CourseAdd(l.ctx, &course.CourseAddRequest{
		Name:    req.Name,
		Teacher: req.Teacher,
		Intro:   req.Intro,
		Price:   float32(req.Price),
		Cover:   req.Cover,
		Video:   req.Video,
	})
	if err != nil {
		return &types.Response{
			Msg:  "课程发布失败",
			Code: "500",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "课程发布成功",
		Code: "200",
		Data: map[string]interface{}{
			"courseAdd": courseAdd,
		},
	}, nil
}
